<template>
  <div >
    <div style="background: #eee; padding: 20px;">
      <Card>
        <i-button type="primary" style="margin-bottom: 16px">押金设置</i-button>
        <Form
          ref="formValidate"
          :model="formValidate"
          label-position="right"
          :label-width="120"
        >
          <FormItem label="多少件包邮" prop="number">
            <Input
            style="width:600px"
              v-model="formValidate.number"
              placeholder="请输入多少件包邮"
            />
          </FormItem>
          <FormItem label="一件多少邮费" prop="postage">
            <Input
            style="width:600px"
              v-model="formValidate.postage"
              placeholder="请输入一件多少邮费"
            />
          </FormItem>
          <FormItem>
            <Button type="primary" @click="handleSubmit('formValidate')"
              >保存</Button
            >
          </FormItem>
        </Form>
      </Card>
    </div>
    <div style="background: #eee; padding: 20px">
      <Card>
        <i-button type="primary" style="margin-bottom: 16px">规则设置</i-button>
        <Form
          label-position="right"
          :label-width="120"
        >
          <FormItem label="会员规则" >
            <Input
              v-model="formValidate1[0].details"
              style="width:600px"
               type="textarea"
              placeholder="请输入会员规则"
            />
          </FormItem>
          <FormItem label="任务规则" >
            <Input
              v-model="formValidate1[1].details"
              style="width:600px"
               type="textarea"
              placeholder="请输入任务规则"
            />
          </FormItem>
          <FormItem label="一番赏规则" >
            <Input
              v-model="formValidate1[2].details"
              style="width:600px"
               type="textarea"
              placeholder="请输入一番赏规则"
            />
          </FormItem>
          <FormItem>
            <Button type="primary" @click="handleSubmit1('formValidate1')"
              >保存</Button
            >
          </FormItem>
        </Form>
      </Card>
    </div>
  </div>
</template>

<script>
import apis from "@/api/comment";
export default {
  components: {
  },
  data() {
    return {
      formValidate: {
        number: "",
        postage: "",
      },
      ruleValidate: {
        number: [
          { required: true, message: "多少件包邮不能为空", trigger: "blur" },
        ],
        postage: [
          { required: true, message: "一件多少邮费不能为空", trigger: "blur" },
        ],
      },
      formValidate1: [
        {
          details:'',
          id:1,
        
        },
        {
          details:'',
          id:2,
        
        },
        {
          details:'',
          id:3,
        
        }
      ],
    };
  },
  mounted() {
    this.getadvertisement();
    this.getadvertisement1();
  },
  methods: {
    getadvertisement() {
      apis
        .get_comment()
        .then((response) => {
          if (response.data.code == 0) {
            var content = response.data.data;
            this.formValidate.number = content.number;
            this.formValidate.postage = content.postage;
          } else {
            this.$Message.error("请求失败!");
          }
        })
        .catch((error) => {
          console.log(error);
          this.$Message.error("请求失败!");
        });
    },
    handleSubmit1() {
     
       
          let data = {
            details: this.formValidate1[0].details,
            id: 1,
          };
          apis.updatedisclaimer1(data).then((response) => {
            if (response.data.code == 0) {
              let data1 = {
                details: this.formValidate1[1].details,
                id: 2,
              };
              apis.updatedisclaimer1(data1).then((response) => {
                if (response.data.code == 0) {
                  let data2 = {
                    details: this.formValidate1[2].details,
                    id: 3,
                  };
                  apis.updatedisclaimer1(data2).then((response) => {
                    if (response.data.code == 0) {
                      this.$Message.success("修改成功!");
                      this.getadvertisement1();
                    } else {
                      this.$Message.error("修改失败!");
                    }
                  });
                } else {
                  this.$Message.error("修改失败!");
                }
              });
            } else {
              this.$Message.error("修改失败!");
            }
          });
        
     
    },
    getadvertisement1() {
      apis
        .get_comment1()
        .then((response) => {
          if (response.data.code == 0) {
            var content = response.data.data;
            this.formValidate1 = content;
          } else {
            this.$Message.error("请求失败!");
          }
        })
        .catch((error) => {
          console.log(error);
          this.$Message.error("请求失败!");
        });
    },
    handleSubmit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          let data = {
            number: this.formValidate.number,
            postage: this.formValidate.postage,
          };
          apis.updatedisclaimer(data).then((response) => {
            if (response.data.code == 0) {
              this.modalAddcase = false;
              this.$Message.success("修改成功!");
              this.getadvertisement();
            } else {
              this.$Message.error("修改失败!");
            }
          });
        } else {
          this.$Message.error("Fail!");
        }
      });
    },
  },
};
</script>

<style scoped>
</style>